package com.eagle.common.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.slf4j.Logger;

import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import com.eagle.common.entity.enums.PageSize;
import com.eagle.common.entity.po.UserRRoles;
import com.eagle.common.entity.po.query.UserRRolesQuery;
import com.eagle.common.entity.vo.PaginationResult;
import com.eagle.common.entity.vo.SimplePage;
import com.eagle.common.exception.BusinessException;
import com.eagle.common.mapper.UserRRolesMapper;
import com.eagle.common.service.UserRRolesService;



/**
 * 
 * 用户角色对应表 业务接口实现
 * 
 */
@Service("userRRolesService")
public class UserRRolesServiceImpl implements UserRRolesService {

private static final Logger logger = LoggerFactory.getLogger(UserRRolesServiceImpl.class);	@Resource
	private UserRRolesMapper<UserRRoles,UserRRolesQuery> userRRolesMapper;

	/**
	 * 根据条件查询列表
	 */
	public List<UserRRoles> findListByParam(UserRRolesQuery param) {
		List<UserRRoles> list = this.userRRolesMapper.selectList(param);
		return list;
	}

	/**
	 * 根据条件查询列表
	 */
	public Integer findCountByParam(UserRRolesQuery param) {
		Integer count = this.userRRolesMapper.selectCount(param);
		return count;
	}

	/**
	 * 分页查询方法
	 */
	public PaginationResult<UserRRoles> findListByPage(UserRRolesQuery param) {
		int count = this.userRRolesMapper.selectCount(param);
		int pageSize = param.getPageSize()==null?PageSize.SIZE15.getSize():param.getPageSize();
		int pageNo = 0;
		if (null != param.getPageNo()) {
			pageNo=param.getPageNo();
		}
		SimplePage page = new SimplePage(pageNo, count, pageSize);
		param.setSimplePage(page);
		List<UserRRoles> list = this.userRRolesMapper.selectList(param);
		PaginationResult<UserRRoles> result = new PaginationResult<UserRRoles>(page, list);
		return result;
	}

	/**
	 * 新增
	 */
	public Integer add(UserRRoles bean) throws BusinessException{
		try {
			return this.userRRolesMapper.insert(bean);
		} catch (Exception e) {
			throw new BusinessException("信息已经存在");
		}
	}

	/**
	 * 批量新增
	 */
	public Integer addBatch(List<UserRRoles> listBean){
		if (listBean == null || listBean.isEmpty()) {
			return 0;
		}
		return this.userRRolesMapper.insertBatch(listBean);
	}

	/**
	 * 根据UserIdAndRoleId修改
	 */
	public Integer updateByUserIdAndRoleId(UserRRoles bean,Integer userId,Integer roleId){
		return this.userRRolesMapper.updateByUserIdAndRoleId(bean,userId, roleId);
	}


	/**
	 * 根据UserIdAndRoleId删除
	 */
	public Integer deleteByUserIdAndRoleId(Integer userId,Integer roleId){
		return this.userRRolesMapper.deleteByUserIdAndRoleId(userId,roleId);
	}


	/**
	 * 根据UserIdAndRoleId获取对象
	 */
	public UserRRoles getUserRRolesByUserIdAndRoleId(Integer userId,Integer roleId){
		return this.userRRolesMapper.selectByUserIdAndRoleId(userId,roleId);
	}

}